<template>
  <div @keyup.enter="getData()">
    <el-form :inline="true">
      <el-form-item>
        <el-input v-model="params.customer_name" placeholder="项目名称查询" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="params.corp_name" placeholder="负责人查询" :clearable="true"></el-input>
      </el-form-item>
      <el-form-item>
        <select-address
          v-model="params.address_code"
          clearable
          placeholder="地址查询"
          :auto-top="true"
          @change="getData()"
        ></select-address>
      </el-form-item>
      <el-form-item>
        <el-button @click="getData()">查询</el-button>
      </el-form-item>
    </el-form>
    <c-table
      border
      v-loading="loading"
      :stripe="false"
      :columns="tableColumns"
      :data="tableData"
      :height="dialogHeight"
    ></c-table>
    <div class="query-pagination">
      <div></div>
      <el-pagination
        layout="total, prev, pager, next, jumper"
        :current-page.sync="params.index"
        :page-size="params.size"
        :total="totalCount"
        @current-change="getData"
      ></el-pagination>
    </div>

    <el-dialog
      :visible.sync="reportVisible"
      :close-on-click-modal="false"
      append-to-body
      top="30px"
      width="1000px"
    >
      <el-tabs v-model="active">
        <el-tab-pane label="合同审批表" name="first">
          <contract-approve-union
            v-if="+relatedData.gua_type === 4"
            :query-id="queryId"
            :process-status="relatedData.process_status"
            view-mode
          ></contract-approve-union>
          <contract-approve
            v-if="+relatedData.gua_type === 2"
            :query-id="relatedData.customer_related_id"
            view-mode
          ></contract-approve>
        </el-tab-pane>
        <!-- <el-tab-pane label="签约登记">
          <contract-registr :query-id="queryId"
                            view-mode></contract-registr>
        </el-tab-pane> -->
        <el-tab-pane label="项目审批表">
          <investigate-approve-view
            v-if="+relatedData.gua_type === 4"
            :query-id="queryId"
            :process-status="relatedData.process_status"
          ></investigate-approve-view>
          <review-file-view
            v-else-if="+relatedData.gua_type === 2"
            :related-data="relatedData"
          ></review-file-view>
        </el-tab-pane>

        <el-tab-pane label="合同附件" name="contract">
          <contract-guard-view :query-id="queryId"></contract-guard-view>
        </el-tab-pane>
        <el-tab-pane label="担保意向函" v-if="+relatedData.ele_letter_status > 0" name="letter">
          <letter-view :query-id="queryId"></letter-view>
        </el-tab-pane>

        <el-tab-pane label="附件">
          <attach-view :queryId="queryId" :visible="reportVisible"></attach-view>
        </el-tab-pane>
      </el-tabs>
    </el-dialog>

    <el-dialog
      :visible.sync="editVisible"
      :close-on-click-modal="false"
      append-to-body
      top="30px"
      width="1000px"
    >
      <pdf-view
        :contractId="docId"
        :view-mode="viewMode"
        :sig-no="sigNo"
        :downName="signType"
      ></pdf-view>
    </el-dialog>
  </div>
</template>

<script>
import taskTableMixin from '@/credit/mixin/task/taskTable'
import SelectAddress from '@/components/select/SelectAddress'
import PdfView from '@/credit/views/county/unionProvince/components/PdfView'
import ContractApprove from '@/credit/views/city/self/components/contractApprove/Main'
import InvestigateApproveView from '@/credit/views/county/unionProvince/components/InvestigateApproveView'
import ReviewFileView from '@/credit/views/county/mission/components/ReviewFileView'
import ContractGuardView from '@/credit/views/county/unionProvince/components/ContractGuardView'
import LetterView from '@/credit/views/county/unionProvince/components/LetterView'
import AttachView from '@/credit/components/AttachView'
export default {
  components: {
    SelectAddress,
    PdfView,
    ContractApprove,
    InvestigateApproveView,
    ReviewFileView,
    ContractGuardView,
    LetterView,
    AttachView,
    // ContractRegistr
  },
  props: {
    routeId: String,
  },
  mixins: [taskTableMixin],
  data() {
    return {
      enumTaskType: {
        37: '担保意向函',
        38: '委托合同',
        39: '反担保合同',
        40: '放款通知书',
      },
      params: {
        index: 1,
        size: 10,
      },
      order: {
        create_time: 'desc',
      },
      tableData: [],
      loading: false,
      totalCount: 0,
      tableColumns: [
        {
          attrs: { label: '主体名称', prop: 'customer_name', minWidth: 135 },
          process: (v, row) => ({
            attrs: { class: 'project-history', attrs: { 'data-history': row.is_history } },
          }),
        },
        { attrs: { label: '负责人', prop: 'corp_name', align: 'center' } },
        { attrs: { label: '地址', prop: 'address', minWidth: 135 } },
        { attrs: { label: '联系电话', prop: 'mobile_no', align: 'center', minWidth: 120 } },
        { attrs: { label: '用章类型', prop: 'signType', align: 'center' } },
        { attrs: { label: '签章发起时间', prop: 'signTime', align: 'center', minWidth: 120 } },
        {
          attrs: { label: '操作', align: 'center', width: 130 },
          operations: [
            {
              content: '签章',
              icon: 'fa fa-gavel',
              event: this.handleEdit,
              ifRender: row => +row.task_status === 0,
            },
            {
              content: '查看',
              icon: 'fa fa-file',
              event: this.handleContractView,
            },
            {
              content: '项目信息',
              icon: 'fa fa-search',
              event: this.handleView,
            },
          ],
        },
      ],
      reportVisible: false,
      relatedData: {},
      docId: '',
      sigNo: '',
      viewMode: true,
      signType: '',
      active: 'first',
      queryId: '',
      editVisible: false,
    }
  },

  created() {
    if (this.routeId) {
      this.editVisible = true
      this.docId = this.routeId
      this.viewMode = true
      this.sigNo = ''
      window.history.replaceState({}, document.title, window.location.href.replace(/\?.*/, ''))
    }
  },
  methods: {
    dataAdapter(item) {
      item.signType = this.enumTaskType[item.task_type] || '-'
      item.signTime = this.$utils.dateFormat(item.create_time, 'yyyy-MM-dd hh:mm')
      return item
    },
    handleView(row = {}) {
      this.active = 'first'
      this.reportVisible = true
      this.queryId = row.customer_related_id
      this.relatedData = { ...row }
    },
    handleEdit(row = {}) {
      this.signType = row.signType
      this.viewMode = false
      this.editVisible = true
      this.docId = row.extra1 || ''
      this.sigNo = row.extra2 || ''
    },
    handleContractView(row = {}) {
      this.signType = row.signType
      this.viewMode = true
      this.editVisible = true
      this.docId = row.extra1 || ''
    },
  },
}
</script>
<style lang="scss" scoped></style>
